﻿using System.Net;
using System.Net.Http;
using System.Web.Http;
using AzureConnection;

namespace PainRatingAPI.Controllers
{
    public class PainRatingController : ApiController
    {
        static readonly Repository Repository = new Repository();

        [HttpGet]
        public HttpResponseMessage AddChild()
        {
            var returnMsg = "PIS!";
            var success = Repository.AddChild();
            if (success)
                returnMsg = "JAAAH!";

            return Request.CreateResponse(HttpStatusCode.OK, new { response = returnMsg });
        }

        [HttpGet]
        public HttpResponseMessage GetChildren()
        {
            var res = Repository.GetChildren();
            return Request.CreateResponse(HttpStatusCode.OK, new { response = res });
        }

        [HttpGet]
        public HttpResponseMessage ValidateCPR(string cpr)
        {
            var child = Repository.ValidateCPR(cpr);
            if (child != null)
                return Request.CreateResponse(HttpStatusCode.OK, new {response = child});

            return Request.CreateResponse(HttpStatusCode.NotFound, new {response = "NotFound"});
        }

        [HttpGet]
        public HttpResponseMessage SetPainScore(string cpr, int score, string note)
        {
            var success = Repository.SetPainScore(cpr, score, note);
            if (success)
                return Request.CreateResponse(HttpStatusCode.Accepted, new {response = "Accepted"});

            return Request.CreateResponse(HttpStatusCode.NotAcceptable, new {response = "NotAcceptable"});
        }

        [HttpGet]
        public HttpResponseMessage GetChild(string cpr)
        {
            var child = Repository.GetChild(cpr);
            if (child != null)
                return Request.CreateResponse(HttpStatusCode.Found, new {response = child});

            return Request.CreateResponse(HttpStatusCode.NotFound, new {response = "NotFound"});
        }
    }
}
